{extend name="../../../view/public/base" /}

{block name="css"}
<style>
    body {
        background-color: #F2F2F2;
    }
</style>
{/block}

{block name="body"}
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form" lay-filter="addForm" autocomplete="off">
                    <!--标识-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">标识</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入标识" class="layui-input" value="" lay-verify='required'>
                        </div>
                    </div>
                    <!--名称-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="请输入名称" class="layui-input" value="" lay-verify='required'>
                        </div>
                    </div>
                    <!--描述-->
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">描述</label>
                        <div class="layui-input-block">
                            <script id="description" name="description" type="text/plain" style="width:100%;height:500px;"></script>
                            <script>
                                //实例化编辑器
                                UE.getEditor('description');
                            </script>
                        </div>
                    </div>
                    <!--配置-->
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">配置</label>
                        <div class="layui-input-block">
                            <script id="config" name="config" type="text/plain" style="width:100%;height:500px;"></script>
                            <script>
                                //实例化编辑器
                                UE.getEditor('config');
                            </script>
                        </div>
                    </div>
                    <!--作者-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">作者</label>
                        <div class="layui-input-block">
                            <input type="text" name="author" placeholder="请输入作者" class="layui-input" value="">
                        </div>
                    </div>
                    <!--版本号-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">版本号</label>
                        <div class="layui-input-block">
                            <input type="text" name="version" placeholder="请输入版本号" class="layui-input" value="">
                        </div>
                    </div>
                    <!--状态:-1=未安装,0=禁用,1=启用-->
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block" id="status">
                                <select name="status" lay-verify="required">
                                    <option value="" >请选择状态</option>
                                    <option value="-1" selected>未安装</option>
                                    <option value="0">禁用</option>
                                    <option value="1">启用</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="submitBtn">立即提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script>
    var layer, form, bwajax, upload, $, laydate;

    layui.use(['layer', 'form', 'bwajax', 'upload', 'laydate'], function () {
        layer = layui.layer;
        form = layui.form;
        bwajax = layui.bwajax.instance();
        upload = layui.upload;
        $ = layui.jquery;
        laydate = layui.laydate;



        //TODO 监听提交按钮
        form.on('submit(submitBtn)', function (obj) {
            data = obj.field;

            if(!data.name) {layer.msg('标识不能为空', {icon: 2});return false}
            if(!data.title) {layer.msg('名称不能为空', {icon: 2});return false}
            if(!data.status) {layer.msg('状态不能为空', {icon: 2});return false}


            //TODO ajax调用后台接口
            bwajax.post("{:Url('add')}", data)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('提交成功', {icon: 1});
                        submitSuccess();
                    } else {
                        layer.msg(response.data.msg, {icon: 2});
                    }
                })

            return false;
        })
    });
</script>
{/block}